/**
 * 主界面左侧的车辆树菜单
 * 根据json数据生成树
 * 基于ztree进行封装
 */

VehicleTree = {}
/**
 *创建树
 */
VehicleTree.createTree = function(id, treeHeight,treeRightMenu,_refershInverval)
{
	this.treeId = id;
	this.updateMap = {};
	this.filterParams = {};//过滤条件
	 this.treeRightMenu = treeRightMenu;
	 //this.treeManager = $("#"+id);
	 this.load(false);
	 this.timerName = "refreshTreeTimer";
	 this.refreshInterval = _refershInverval;
	 this.strInterval = this.refreshInterval + 's';
	 var me = this;
	 this.videoAuthorized = false;
	 this.nodeMap = {};
}

//更新节点的图标状态
VehicleTree.updateTreeNode = function(data)
{
	var me = this;	
	$.each(data, function (i, n) {
		//var nodes = me.treeManager.getNodesByParam("id",n.id);
		//if (nodes && nodes.length > 0){
			//var node = nodes[0];
			var node = me.nodeMap[n.id];
			if(node)
		   {
			   node.iconSkin = n.iconSkin;
			   node.name = n.name;
			   me.treeManager.updateNode(node);
		   }

		//}else
			//me.updateMap[n.id] = n;
   });
   /*
	author:shinion
	date:2019-01-15
	修改代码，增加更新地址等信息
	在更新节点之后，完成排序
	*/
	me.updateNodesAlarmInfo(data);
	// console.log("更新车辆树数据:"+data.length+"条");
	// console.log(data);
}

/**
 * 获得当前选中的节点
 */
VehicleTree.getSelected=function()
{
     var nodes = this.treeManager.getSelectedNodes();
	 if(nodes && nodes.length > 0)
		 return nodes[0];

	 return null;
}


VehicleTree.getSelectedPlateNo=function()
{
	var node = this.getSelected();
	if(node != null && node.isParent == false)
	{
			var plateNo = node.attributes["plateNo"];
			return plateNo;
	}
	return "";
}
VehicleTree.filter = function(params)
{
	this.filterParams = params;
	params.filter = true;
	this.load(false);
}

VehicleTree.clearFilter = function()
{
	this.filterParams = {filter:false};
	this.load(false);
}

VehicleTree.initTree = function(treeNodes)
{
	var me = this;

	/*
	author:shinion
	date:2019-01-15
	修改代码，增加更新地址等信息
	在初始化车辆数之前即完成更新排序
	*/
	me.updateNodesAlarmInfo(treeNodes);


	var setting = {
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: false
				}
			},
			callback: {
				onCheck: me.onCheck,
				onRightClick: me.OnRightClick,
				onDblClick:me.onDblClick,
				onClick: me.onClick,
				beforeExpand:me.beforeExpand,//author:shinion date:2019-02-20
			},
			view: {
				nameIsHTML:true
				//addHoverDom: me.addHoverDom,
				//removeHoverDom: me.removeHoverDom
			}
		};
    $.fn.zTree.init($("#"+ this.treeId), setting, treeNodes);
	
	 this.treeManager = $.fn.zTree.getZTreeObj(this.treeId);

   var nodes = this.treeManager.getNodes();
   if(nodes && nodes.length > 0)
	{
	   var rootNode = nodes[0];
	   this.treeManager.expandNode(rootNode, true);
	   
	   var start = new Date();
	   //this.saveNodeMap(rootNode);
	   $.each(nodes,function(i,n)
		{		   
			me.nodeMap[n.id] = n;
		    me.saveNodeMap(n);
		});

	   var end = new Date();
	   var interval = 0.001 * (end - start) ;
	   //if(console)
		   //console.log("saveNodeMap耗时:"+ interval+"秒");
	}
}

VehicleTree.saveNodeMap = function(node)
{
	var me = this;
   if(node.children && node.children.length > 0)
	{
	   var children = node.children;
	   $.each(children,function(i,n)
		{		   
	        me.nodeMap[n.id] = n;
		    me.saveNodeMap(n);
		});
	}

}

VehicleTree.load = function(isUpdate)
{
	if(isUpdate == false)
	{
		this.updateMap = {};
		jQuery('#'+this.treeId).showLoading(); 

	}
	var me = this;
	var treeManager = this.treeManager;
	var treeRightMenu = this.treeRightMenu;
	var url = globalConfig.webPath+"/vehicle/getVechecileTree.action";
	//var params = {updateNode:update};
	this.filterParams.updateNode = isUpdate;
	var filter = this.filterParams.filter;
     $.ajax({
            type: "POST",
            url: url,
			data:this.filterParams,
			error:function(){
			   //alert("网络连接错误，无法读取数据!");
               //Utility.done();
			},
            success: function(data){
				var treeData = data.treeData;
				if(treeData == undefined || data.error == "SessionInvalid")
				{
					//Session失效，跳往登录页面重新登录
					window.location.href=globalConfig.webPath + "/logout.action";
				}
				
				

				if(isUpdate == false)
				{
					var start1 = new Date();
					me.initTree(treeData);
					var end1 = new Date();
					var interval1 = 0.001 * (end1 - start1) ;
					//if(console)
					   //console.log("载入树节点"+treeData.length+"条数,耗时:"+ interval1+"秒");
					//启动定时器不断的更新车辆树
					 $('body').everyTime(me.strInterval, me.timerName,function(){
						me.load(true);//更新模式
					 });
				}else
				{
					var start = new Date();
					me.updateTreeNode(treeData);
					var end = new Date();
					var interval = 0.001 * (end - start) ;
					//if(console)
					  // console.log("更新树节点"+treeData.length+"条数,耗时:"+ interval+"秒");
				}
				
				



				var onlineInfo = data;
				$("#spanTotal").html(onlineInfo.totalNum);
				$("#spanGpsOnline").html(onlineInfo.onlineNum);
				$("#spanGpsOffline").html(onlineInfo.offlineNum);
				$("#spanParking").html(onlineInfo.parkingNum);
				$("#spanOnlineRate").html(onlineInfo.onlineRate);
				$("#spanOnlineUserNum").html(onlineInfo.onlineUserNum);
				
		        jQuery('#'+me.treeId).hideLoading(); 
            },
			error:function()
		    {
		        jQuery('#'+me.treeId).hideLoading(); 
			}
        });

}

/*
author:shinion
date:2019-01-12
更新节点的相关数据信息：
	1.通过节点，获取车辆列表
	2.通过车辆列表，获取车辆实时信息
	3.更新实时信息到车辆列表中
*/
VehicleTree.updateNodesAlarmInfo = function(treeData){
	try {
		var me = this;
		if (treeData.length > 0) {
			// console.log("更新车辆树节点个数:"+treeData.length);
			// console.log(treeData);
			$.each(treeData, function (i, node) {
				me.getVehicleNodes(node);
			});
			// console.log("更新数据后节点：");
			// console.log(treeData);
		}
		
	} catch (error) {
		console.error("更新车辆树相关信息错误：" + error);
	}
}
/*
author:shinion
date:2019-01-12
递归获取所有的车辆节点
	1.判断当前节点是否为组织节点，如果不是，不操作
	2.如果当前节点为组织节点，那么遍历当前节点的子节点
		2.1.如果子节点为组织节点，那么递归遍历子节点的子节点
		2.2.如果子节点为车辆节点，那么更新车辆信息，并且根据标记值确定是否重排序车辆树
 */
VehicleTree.getVehicleNodes = function(node){
	var me = this;
	try {
		var strId = node.id;
		if(strId.indexOf("d")==0){
			//当前为组织节点
			var sortFlg = false;//标记是否需要排序
			var nodesTemp = node.children;
			if(nodesTemp && nodesTemp.length > 0){
				//遍历节点的子节点
				$.each(nodesTemp,function(i,nodeTemp){
					var strId2 = nodeTemp.id;
					// console.log(strId2);
					if(strId2.indexOf("d")==0){
						//子节点为组织节点
						//继续递归当前节点子节点
						// console.log("getVehicleNodes递归");
						me.getVehicleNodes(nodeTemp);
					}else if(strId2.indexOf("v")==0){
						//子节点为车辆节点
						//更新车辆节点的数据
						// console.log("设置车辆节点数据");
						me.setVehicleNodeInfo(nodeTemp);
						sortFlg = true;

					}
				});
				if(sortFlg){
					//排序,每次只要调用这个方法，必定有刷新
					//对车辆列表进行排序
					me.sortNodes(nodesTemp);
				}
			}
		}else if(strId.indexOf("v")==0){
			//非组织节点，车辆节点
			/*
			非组织节点，车辆节点
			1.获取父节点
			2.
			*/
			// console.log("车辆所在组织数据");
			var node = me.nodeMap[strId];
			if(node){
				// console.log(me.treeId);
				var parentNode = node.getParentNode();
				// console.log(parentNode.id);
				me.getVehicleNodes(parentNode);//调用递归方法，排序
			}
		}
	} catch (error) {
		console.error("获取车辆节点错误："+error);
	}
}
/*
author:shinion
date:2019-01-12
设置当前车辆节点的数据
	根据当前节点的报警信息和在线标记，设置显示优先级
	1.如果不在线，优先级为1
	2.如果在线，优先级设为2
		2.1如果定位无效，优先级设为3，有效不赋值
		2.2如果有报警信息，优先级设为4，没有则不赋值
	根据优先级，从高到低进行排序
*/
VehicleTree.setVehicleNodeInfo = function(vehicleNode){
	//定义报警标记，0表示当前节点没有报警信息，1表示有报警信息
	try {
		// console.log(vehicleNode);
		var me = this;
		var attributes = vehicleNode.attributes;
		if(attributes){
			//获取实时地址
			var location = attributes.location;
			if(location){
				//地址不为空
				vehicleNode.name =attributes.plateNo +"&nbsp;&nbsp;&nbsp;"+ me.getCityName(location);
				// console.log(vehicleNode.name);
			}
			//获取状态信息
			var alarmStatus = attributes.alarmStatus;//报警状态
			var alarmTemp = 0;//报警
			if(alarmStatus){
				alarmTemp = alarmStatus.indexOf("1");
			}
			var onlineTemp = attributes.online;//在线
			var validTemp = attributes.valid;//定位

			//进行优先级赋值
			var showFlg = 1;
			if(onlineTemp){
				//在线
				showFlg = 2;
				if(alarmTemp > 0){
					//有报警信息
					showFlg = 4;
				}
			}

			//不论是否在线，无效定位优先级都是3
			if(!validTemp){
				//定位无效
				showFlg = 3;
			}

			//优先级赋值
			attributes.showFlg = showFlg;

			// var strTemp = "plateNo="+attributes.plateNo + ",alarmTemp="+alarmTemp+",onlineTemp="+onlineTemp+",validTemp="+validTemp+",showFlg="+attributes.showFlg;
			// console.log(strTemp);
		}
	} catch (error) {
		console.error("更新车辆信息失败:"+error);
	}
}
/*
根据地址，获取市的名称
	1.首先去掉省级名称：
		1.1查看“省”的索引，如果大于1小于5，则存在，
		1.2.如果省级不存在，则查看“市”，如果”市“的索引大于1小于4，则存在直辖市
		1.3.如果直辖市不存在，则查看“自治区”，如果“自治区的索引大于1，则存在，否则不存在
	2.如果省级存在，则字符串截取省级以后的部分，截取10个
	3.从截取的字符串中，查看“市”的索引，如果索引大于1则存在，否则不存在
	3.2如果“市”索引不存在，则查找“区”索引，如果区索引大于1，则存在，
	3.3如果索引存在，则截取从零到（索引+1）的字符串，然后返回该字符串
*/
VehicleTree.getCityName = function(location){
	try {
		var returnStr = "";
		var length = location.length;
		var index1 = location.indexOf("省");
		if(index1>5 || index1<1){
			//获取省失败，获取直辖市
			index1 = location.indexOf("市");
			if(index1>3 || index1<1  ){
				//直辖市不存在
				index1 = location.indexOf("自治区");
				if(index1 <0)//如果都不存在，则返回空字符串
				return returnStr;
			}
		}
		var strtemp = location.substring((index1+1),10);//截取省级单位后面的十个数字

		//查找市级单位
		var index2 = strtemp.indexOf("市");
		if(index2 > 7 || index2<2){
			//市不存在
			index2 = strtemp.indexOf("区");
			if(index2 >5 || index2 < 2){
				//区不存在
				return returnStr;
			}
		}

		//返回地址
		returnStr = strtemp.substring(0,(index2+1));
		return returnStr;

	} catch (error) {
		console.error("获取城市地址错误："+error);
	}
}
/*
排序车辆节点
	把一个组织节点的车辆节点进行排序，有报警信息的，排到前面，没有报警信息的，在后面
	1.定义一个索引，指向可以交换的数组编号
	2.遍历列表，如果当前节点有报警信息，则和索引指向的编号数组交换，索引后移
*/
VehicleTree.sortNodes = function(nodesTemp){
	var me = this;
	// console.log("排序");
	// console.log(nodesTemp);
	var sortIndex = me.sortNodesByFlg(0, 4, nodesTemp);
	if (sortIndex >= 0) {
		sortIndex = me.sortNodesByFlg(sortIndex, 3, nodesTemp);
		if (sortIndex >= 0) {
			sortIndex = me.sortNodesByFlg(sortIndex, 2, nodesTemp);
		}
	}
}
/*
排序车辆节点
	需要排序的节点列表，排序起点，需要排序的优先级
*/
VehicleTree.sortNodesByFlg = function(startIndex,flg,nodeList){
	var index = startIndex;//定义索引，指向可以交换的数组编号
	try {
		var me = this;
		if(nodeList.length > index){
			for(var i=index ; i<nodeList.length ; i++){
				if(nodeList[i].attributes.showFlg == flg){
					//如果为需要排序的优先级
					me.changeNode(nodeList,index,i);
					index++;
				}
			}
		}
		return index;
	} catch (error) {
		console.error("节点排序错误："+error);
		return -1;
	}
}

//交换两个节点
VehicleTree.changeNode = function(nodeList,index1,index2){
	try {
		if(index1 != index2){
			var temp = nodeList[index1];
			nodeList[index1] = nodeList[index2];
			nodeList[index2] = temp;
			// console.log("交换：");
			// console.log(nodeList[index1]);
			// console.log(nodeList[index2]);
		}
	} catch (error) {
		console.error("交换节点错误："+error);
	}
}

/**
 tree的onclick事件
 */
var lastSelectedNode = null;
var lastVehicleNode = null;
VehicleTree.onClick = function(event, treeId, node, clickFlag)
{
    //通道节点
    if(lastSelectedNode!=null && node != lastVehicleNode && node.getParentNode() != lastVehicleNode)
    {
        lastSelectedNode.removeClass("vehicle-selected-node");
        $(".tree_shortcut_toolbar").remove();
        lastSelectedNode = null;
        lastVehicleNode = null;
    }
    var strId = node.id;
    //表明点击的是车辆节点
    if(strId.indexOf("v") == 0)
    {
        var vehicleId = strId.substring(1);
        //var plateNo = node.attributes["plateNo"];
        var plateNo = node.name;
        plateNo = plateNo.substring(0, plateNo.indexOf('&'));
        MyMap.showVehicleOnMap(vehicleId);
        HistoryRoutePanel.setPlateNo(plateNo);
        RealDataGrid.setPlateNo(plateNo,vehicleId);
        if(node != lastVehicleNode)
        {
            lastSelectedNode = $("#" + node.tId + "_a").parent();
            if(VehicleTree.videoAuthorized == true)
			{
                $("#" + node.tId + "_a").after('<div class="tree_shortcut_toolbar" id="tbar_' + node.id + '"><a  href="javascript:InfoWindow.openCommandWindow(\'REAL_MONITOR\','+ vehicleId + ', \''+ plateNo + '\',\'icon-greencar\')">跟踪</a>&nbsp;|&nbsp;<a  href="javascript:addHisrouteTab();">回放</a>&nbsp;|&nbsp;<a id="aplay_' + node.id + '" href="javascript:VehicleTree.playVideo(\''+ node.id + '\')">实时视频</a></div>');

            }  else
			{
                $("#" + node.tId + "_a").after('<div class="tree_shortcut_toolbar" id="tbar_' + node.id + '"><a  href="javascript:InfoWindow.openCommandWindow(\'REAL_MONITOR\','+ vehicleId + ', \''+ plateNo + '\',\'icon-greencar\')">跟踪</a>&nbsp;|&nbsp;<a  href="javascript:addHisrouteTab();">回放</a>&nbsp;|&nbsp;<a href="javascript:InfoWindow.openCommandWindow(\'VEHICLE_INFO\','+ vehicleId + ', \''+ plateNo + '\',\'icon-greencar\')">车辆信息</a></div>');
			}
            lastSelectedNode.addClass("vehicle-selected-node");
        }
        lastVehicleNode = node;

        var refresh_tab = $('#mainTab').tabs('getSelected');
        if(refresh_tab)
        {
            var title = refresh_tab.panel('options').title;
            if(title.indexOf("历史视频") >= 0)
            {
                iframeWindow= document.getElementById("videoPlayBackIFrame");//refresh_tab.find('iframe')[0];
                iframeWindow.contentWindow.setVideoInfo(plateNo, node.simNo,vehicleId);
            }
        }

    }
}

/*
tree 的展开前事件
*/
VehicleTree.beforeExpand = function(treeId,treeNode){
	var strId = treeNode.id;
	if(strId.indexOf("v") == 0){
		// console.log("展开事件");
		//展开车辆下的节点
		// console.log(treeNode);
		VehicleTree.beforeOpenVehicleNode(treeId,treeNode);
		// return false;
	}
	return true;
}

/*
开始展开车辆节点方法
*/
VehicleTree.beforeOpenVehicleNode = function(treeId,treeNode){
	var me = this;
	// console.log("开始展开车辆节点事件 : ");
	if(treeNode.channelsData == undefined){
		//未保存通道数据
		// treeNode.channelsData = treeNode.children;
	}
	//首先节点置空
	// treeNode.children = [];

	var strId = treeNode.id;
	var vehicleId = parseInt(strId.substring(1));
	if(isNaN(vehicleId)){
		//如果获取不到车辆id，则直接退出
		return ;
	}

	//开始获取数据
	var vehicleChannelsDataStr = "";
	var url = globalConfig.webPath + "/vehicleRealTimeVideo/getChannelDataStr.action";
	var param = {
		vehicleId:vehicleId,
	};
	Utility.getAjaxData(url,JSON.stringify(param),function(data){
		// console.log("获取到数据库中的通道信息数据  ： ");
		// console.log(data);
		if (data.success) {
			//查询成功
			if (data.data.length > 0) {
				vehicleChannelsDataStr = data.data[0].channelsDataStr;
			}
		}
		//不论是否获取数据库成功，都显示设置页面
		// console.log("当前车辆的通道数据为：" + vehicleChannelsDataStr);
		//根据获取的信息展开车辆节点
		VehicleTree.expandVehicleNode2(treeNode,vehicleChannelsDataStr);
		if(me.treeManager){
			// me.treeManager.expandNode(treeNode, true, false, true, false);
		}
	});
	
}

//根据通道数据显示车辆节点
VehicleTree.expandVehicleNode2 = function(treeNode,vehicleChannelsDataStr){
	var showAllFlg = false;
	if(vehicleChannelsDataStr == ""){
		showAllFlg = true;
	}
	var channels = vehicleChannelsDataStr.split(",");
	// console.log("解析后的数组为：");
	// console.log(channels);
	if(channels.length > 0){
		if(this.treeManager && treeNode.children){
			var num = treeNode.children.length;
			for(var i=0 ; i<num ; i++){
				var node = treeNode.children[i];
				// console.log("设置第"+(i+1)+"个节点的状态");
				if(channels.indexOf(''+(i+1)) > -1 || showAllFlg){
					this.treeManager.showNode(node);
				}else{
					// treeNode.children[i].isHidden = true;//隐藏
					this.treeManager.hideNode(node);
				}
			}
		}
	}

}



VehicleTree.addHoverDom = function(treeId, node)
{
    if(node.isParent == false)
	{
		if ($("#tbar_"+node.id).length>0) return;
	     var strId = node.id;
		 var vehicleId = strId.substring(1);
		 var plateNo = node.attributes["plateNo"];
		 var aObj = $("#" + node.tId + "_a");
	     aObj.parent().append('<div class="tree_shortcut_toolbar" id="tbar_' + node.id + '"><a  href="javascript:InfoWindow.openCommandWindow(\'REAL_MONITOR\','+ vehicleId + ', \''+ plateNo + '\',\'icon-greencar\')">跟踪</a>&nbsp;|&nbsp;<a  href="javascript:addHisrouteTab();">回放</a>&nbsp;|&nbsp;<a href="javascript:InfoWindow.openCommandWindow(\'VEHICLE_INFO\','+ vehicleId + ', \''+ plateNo + '\',\'icon-greencar\')">车辆信息</a></div>'); 
		 aObj.parent().addClass("vehicle-selected-node");
    }
}


VehicleTree.removeHoverDom = function(treeId, node) {
	$(".tree_shortcut_toolbar").remove();
	var aObj = $("#" + node.tId + "_a");
	aObj.parent().removeClass("vehicle-selected-node");
}

VehicleTree.OnRightClick = function(event, treeId, treeNode) {
	if(treeNode.id.indexOf("v") != 0)
		return; //如果不是车辆节点，就不弹出右键命令菜单
			if (!treeNode && event.target.tagName.toLowerCase() != "button" && $(event.target).parents("a").length == 0) {
				 VehicleTree.treeManager.cancelSelectedNode();
				VehicleTree.showRMenu("root", event.clientX, event.clientY);
			} else if (treeNode && !treeNode.noR) {
				VehicleTree.treeManager.selectNode(treeNode);
				VehicleTree.showRMenu("node", event.clientX, event.clientY);
			}
		}

VehicleTree.showRMenu = function(type, x, y) {
    if(VehicleTree.treeRightMenu)
							{
								VehicleTree.treeRightMenu.menu('show',{
									left: x,
									top: y
								});
							}
}

VehicleTree.playVideo = function(nodeId)
{
	var aObj = $("#aplay_" + nodeId);
    var node = this.nodeMap[nodeId];
	if(aObj.html() == "实时视频")
	{
		/*
		author:shinion
		date:2019-01-07
		点击实时视频按钮
			1.按钮显示为停止播放
			2.根据节点信息，播放视频
		*/
		aObj.html("停止播放");
		// VehicleTree.playVideoByVehicleTreeNode(node);
		//播放新视频
		VehicleTree.playerNewVideoByTreeNode(node);
	}else
	{
		/*
		author：shinion
		date：2019-01-07
		点击停止播放按钮
			1.按钮显示为实时视频
			2.获取通道号
			3.停止播放实时视频
		*/
		aObj.html("实时视频");
		
		if(RealTimeVideoPlayersTemp != null){
			RealTimeVideoPlayersTemp.doStopAll();
		}
		//以下注释掉代码为原有代码，不删除，保留备用
        // var children = node.children;
        // if(children.length > 0)
        // {
        //     var vehicleId = node.id.substring(1);
        //     var simNo = node.simNo;
        //     var plateNo = node.name;
        //     //plateNo = plateNo.substring(0, plateNo.indexOf('&'));
        //     //var channelName = [];
        //     var channelId = [];
        //     for(var m = 0; m < children.length; m++)
        //     {
        //         var ch = children[m];
        //         channelId.push(m+1);
        //         //channelName.push(plateNo + " " + ch.name);
        //     }
        //     MyVideoPlayer.stopChannelPreview(vehicleId,simNo, channelId);
        // }
	}
}

/*
author:shinion
date:2019-02-12
播放新实时视频信息
*/
VehicleTree.playerNewVideoByTreeNode = function(node){

	console.log("vehicleTree--->开始视频");
	// RealTimeVideoPlayers.test("vehicleTree.js");
	
	addVideoPanelTab();


	var children = node.children;
	if(children.length > 0){

		var nodeId = node.id;
		var vehicleId = nodeId.substring(1);
        var simNo = node.simNo;
        var plateNo = node.name;
		plateNo = plateNo.substring(0, plateNo.indexOf('&'));
		// var vehicleChannelStr = "1,5,6";
		var vehicleChannelStr = "";
		
		var obj = {
			simNo: simNo,
			plateNo: plateNo,
			videoChannelNum:children.length,
			vehicleId:vehicleId,
			vehicleChannelStr:vehicleChannelStr,
		};
		//初始化视频
		if(RealTimeVideoPlayersTemp != null){
			RealTimeVideoPlayersTemp.initShplayers2(obj,"");
		}
	}
}

/*
author：shinion
date：2019-01-07
通过车辆树节点，获取相关信息，播放实时视频
*/

VehicleTree.playVideoByVehicleTreeNode = function(node)
{
	//author：shinion
	//date：2019-01-07
	//获取视频播放控件，即实时视频页面，如果不存在，则添加实时视频页面到选项卡中
    if(MyVideoPlayer.getVideoHandler() == null)
    {
        addVideoPanelTab();
	}
	/*
	author:shinion
	date:2019-01-07
	获取播放需要的信息数据
		1.车辆相关信息，通道号，通道名称等
		2.调用MyVideoPlayer的previewVideo方法播放视频
	*/
    var children = node.children;
    if(children.length > 0)
    {
    	var nodeId = node.id;
        var vehicleId = nodeId.substring(1);
        var simNo = node.simNo;
        var plateNo = node.name;
        plateNo = plateNo.substring(0, plateNo.indexOf('&'));
        var channelName = [];
        var channelId = [];
        for(var m = 0; m < children.length; m++)
        {
            var ch = children[m];
            channelId.push(m+1);
            channelName.push(plateNo + " " + ch.name);
        }
        MyVideoPlayer.previewVideo(vehicleId,simNo, channelId,channelName);
        var aObj = $("#aplay_" + nodeId);
        if(aObj && aObj.html() == "实时视频")
        {
            aObj.html("停止播放");
        }
    }
}

/**
 tree的双击事件
 */
VehicleTree.onDblClick = function(event, treeId, node, clickFlag)
{
	if(this.videoAuthorized == false)
		return;

	addVideoPanelTab();


	// console.log("node.isParent : " + node.isParent);
	if(node.isParent != undefined  && node.isParent == false && node.id.indexOf("ch") >= 0 ){
		var parentNode = node.getParentNode();
        var chNodeId = node.id;
        var vehicleId = parentNode.id.substring(1);
        var index = chNodeId.lastIndexOf("_");
        var channelId = chNodeId.substring(index+1,chNodeId.length);
        var simNo = parentNode.simNo;
        var plateNo = parentNode.name;
		plateNo = plateNo.substring(0, plateNo.indexOf('&'));
		
		var obj = {
			simNo: simNo,
			plateNo: plateNo,
			videoChannelNum:parentNode.children.length,
			vehicleId:vehicleId,
			name:"临时数据",
		};


		if(RealTimeVideoPlayersTemp != null){
			// console.log("双击通道，开始添加通道视频");
			// console.log(obj);
			RealTimeVideoPlayersTemp.addOneChannelData(obj,""+channelId);//添加通道
		}

	}else if(node.id.indexOf("v") >= 0){
		VehicleTree.playerNewVideoByTreeNode(node);
	}


	//以下为原有代码，不删除，注释保留
    // if(node.isParent == false && node.id.indexOf("ch") >= 0 )
    // {
    // 	if(MyVideoPlayer.getVideoHandler() == null)
	// 	{
    //         addVideoPanelTab();
	// 	}
    //     var parentNode = node.getParentNode();
    //     var chNodeId = node.id;
    //     var vehicleId = parentNode.id.substring(1);
    //     var index = chNodeId.lastIndexOf("_");
    //     var channelId = chNodeId.substring(index+1,chNodeId.length);
    //     var simNo = parentNode.simNo;
    //     var plateNo = parentNode.name;
    //     plateNo = plateNo.substring(0, plateNo.indexOf('&'));
    //     //var channelName = parentNode.attributes["plateNo"] + " " + node.name;
    //     var channelName = plateNo + " " + node.name;
    //     MyVideoPlayer.previewVideo(vehicleId,simNo, [channelId],[channelName]);
    // }else if(node.id.indexOf("v") >= 0){
    //     VehicleTree.playVideoByVehicleTreeNode(node);
	// }
}

VehicleTree.getCheck = function(node)
{
	var s = "";
	var me = this;
	$.each(node.children1, function (i, n) {
		var strId = n.id;
		if(n.leaf && strId.indexOf("v")== 0)
		{
           s += strId.substring(1)+",";			
		}else if(n.children1 && n.children==null)
		{
			s+= me.getCheck(n);
		}
	});

	return s;
}

/**
 tree的oncheck事件
 */
VehicleTree.onCheck = function(e, treeId, node)
{
	var me = this;
	var nodes = VehicleTree.treeManager.getCheckedNodes(true);
	//author:shinion date:2019-01-15 测试输出车辆信息
	console.log("勾选中的车辆");
	console.log(nodes);
    if(nodes.length > 1000)
    {
        $.messager.alert('提示','选取车辆数不能超过1000辆');
        return;
    }

    var s = '';
	var me = this;
    for (var i = 0; i < nodes.length; i++) {
		var n = nodes[i];
		var strId = nodes[i].id;
		//判断车辆节点
		if(strId.indexOf('v') == 0)
		{
            s += strId.substring(1)+",";
		}else if(n.children1 && n.children == null)
		{
			//s+=me.getCheck(n);
		}
    }
	VehicleTree.selectVehicleIds = s;
	RealDataGrid.selectVehicleIds = VehicleTree.selectVehicleIds;
	VehicleTree.register();
	if(nodes.length == 0)
	{
		RealDataGrid.clear();//如果什么也没选，就清除表格数据；
		MyMap.clearAllVehicle();//清除地图上的车辆地标
	}
}

VehicleTree.register=function()
{
	var url = globalConfig.webPath+"/realData/registerVehicles.action"
	var params = {registerVehicleIds:VehicleTree.selectVehicleIds};
     $.ajax({
            type: "POST",
            url: url,
			data:params,
			error:function(){
			   //alert("网络连接错误，无法读取数据!");
               //Utility.done();
			},
            success: function(data){
				 //刷新实时表格数据
				 RealDataGrid.refresh(false);	
            }
        });
}
/**
 * 如果用户在界面上选择的是在树上过滤查找车辆，则需要根据过滤结果在地图上更新定位位置；
 */
VehicleTree.createVehicleOnMap=function(treeData)
{
	for(var m = 0; m < treeData.length; m++)
	{
		var node = treeData[m];
		if(node.leaf == true)
		{
			var vehicleId = node.id.substring(1);
			MyMap.showVehicleOnMap(vehicleId);//调用地图类的显示车辆信息在地图上的函数
		}else if(node.children && node.children.length > 0)
		{
			VehicleTree.createVehicleOnMap(node.children);//如果不是车辆节点，递归调用下级
		}
	}
}
